//
//  NetInsurance.m
//  carcareIOS
//
//  Created by ileo on 16/7/27.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "NetInsurance.h"
#import "AIUserInfo.h"
#import "NetEngineServer.h"
#import "InsurenceNorModel.h"
@implementation NetInsurance

+(void)insurancePolicyStatusFinish:(void (^)(PolicyModel *model,NSArray * insureModelArr))finish fail:(void (^)())fail{
    [[[__SELF request:@"/insurance/policyStatus" withParams:nil type:REQUEST_GET] requestWithLoad:RequestLoadShowLoading|RequestLoadShowErrorTips] requestSuccess:^(id JSON) {
        if (finish) {
            PolicyModel *model = [[PolicyModel alloc] initWithDic:JSON[@"policyInfo"]];
            NSMutableArray * tempList = [NSMutableArray arrayWithCapacity:[JSON[@"policyList"]count]];
            for (int index = 0; index < [JSON[@"policyList"]count]; index ++) {
                InsurenceNorModel * insuModel = [[InsurenceNorModel alloc] initWithDic:JSON[@"policyList"][index]];
                if (![insuModel.discount isNotNil]) {
                    insuModel.discoutNoDataStr = (model.status == 1 ? @"" : @"折扣未知");
                    insuModel.discoutNoDataDetailStr = (model.status == 1 ? @"" : @"上传保单可知");
                }
                [tempList addObject:insuModel];
            }
            NSArray * insuArray = [NSArray arrayWithArray:tempList];
            finish(model,insuArray);
        }
    } failure:^(id JSON) {
        if (fail) {
            fail();
        }
    }];
}

+(void)insuranceCheckInfo:(NSDictionary *)infos finish:(void (^)())finish{
    [[[__SELF request:@"/insurance/autoCheck" withParams:infos type:REQUEST_GET] requestWithLoad:RequestLoadShowLoading|RequestLoadShowErrorTips] requestSuccess:^(id JSON) {
        if (finish) {
            finish();
        }
    }];
}

+(void)insuranceUploadPolicyImg:(NSString *)img finish:(void (^)())finish{
    [[[__SELF request:@"/insurance/manualCheck" withParams:@{@"imgUrl":img} type:REQUEST_GET] requestWithLoad:RequestLoadShowLoading|RequestLoadShowErrorTips] requestSuccess:^(id JSON) {
        if (finish) {
            finish();
        }
    }];
}

-(NSDictionary *)requestCommonParams{
    if (![USERINFO.session isNotNil]) {
        return nil;
    }
    return @{@"userid":@(USERINFO.userID),@"session":USERINFO.session};
}

@end
